<?php
	Class Thread extends MessagesAppModel
	{
		var $name = 'Thread';
		
		var $hasMany = array('Message'=>array(
			'className' => 'Messages.Message',
			'order'=>'Message.created DESC'
		));
		
		var $additionalFields = array('lastMessage');
		var $cacheFields = array('lastMessage'=>'+2 minutes');
		
		function lastMessage($result)
		{
			$message = $this->Message->find('first',array('conditions'=>array('thread_id'=>$result[$this->alias]['id']),'order'=>"created desc",'recursive'=>-1));
			return $message;
		}
	}
?>